﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace AnesSystem.ViewModels
{
    public class PacuRecordTimeCtrlViewModel : MultitonBaseViewModel
    {
        #region Variables
        private ObservableCollection<FrameworkElement> _timeList;
        private int _initMargin;

        #endregion


        #region Constructor
        public PacuRecordTimeCtrlViewModel(int page)
        {
            CurPage = page;
            _timeList = new ObservableCollection<FrameworkElement>();
        }

        public ObservableCollection<FrameworkElement> TimeList
        {
            get
            {
                return _timeList;
            }

            set
            {
                _timeList = value;
            }
        }

        public int InitMargin
        {
            get
            {
                return _initMargin;
            }

            set
            {
                _initMargin = value;
            }
        }

        #endregion


        #region Properties


        #endregion


        #region 依赖属性


        #endregion


        #region Event


        #endregion


        #region PrivateMethods
        public void Clear()
        {
            TimeList.Clear();

        }


        #endregion


        #region Public/ProtectedMethods



        public override void Refresh()
        {
            Clear();
            InitData();
        }

        public override void InitData()
        {
            DateTime pacuRecordStartTime = DataManager.Instance.CurrentPatientLink.Status.PacuStartTime;
            DateTime startTime = pacuRecordStartTime.AddHours((CurPage - 1) * 4);
            DateTime date = startTime;
            for (int i = 0; i <= 48; i++)
            {
                TextBlock text = new TextBlock();
                if (date.Minute % 30 == 0)
                {
                    text.Text = date.ToString(DateFormat.DATE_FORMAT_STR_HM);
                    text.FontSize = 16;
                    text.Tag = date;
                    TimeList.Add(text);

                }


                date = date.AddMinutes(5);
            }
        }

        public void SetRealTimeLocation()
        {
            //DateTime pacuRecordStartTime = DataManager.Instance.CurrentPatientLink.Status.PacuStartTime;
            //int span = (((DateTime)TimeList[0].Tag - pacuRecordStartTime).Minutes) / 5;
            //TimeList[0].Margin = new Thickness(span * LocationUtil.RealTimeItem_Width - TimeList[0].ActualWidth / 2, 0, 0, 0);
            //for (int i = 1; i < TimeList.Count; i++)
            //{
            //    TimeList[i].Margin = new Thickness(LocationUtil.RealTimeItem_Width * 6 - TimeList[i].ActualWidth, 0, 0, 0);
            //}
            double height = 41.38;
            DateTime pacuRecordStartTime = DataManager.Instance.CurrentPatientLink.Status.PacuStartTime;
            int span = (((DateTime)TimeList[0].Tag - pacuRecordStartTime).Minutes) / 5;
            TimeList[0].Margin = new Thickness(span * LocationUtil.RealTimeItem_Width - height / 2, 0, 0, 0);
            for (int i = 1; i < TimeList.Count; i++)
            {
                TimeList[i].Margin = new Thickness(LocationUtil.RealTimeItem_Width * 6 - height, 0, 0, 0);
            }
        }

        #endregion


        #region EventHandlers


        #endregion

    }
}

